 export function rorate1(arr: number[], k: number): number[] {
  const length = arr.length
  if (!k || length === 0) return arr
  const step = Math.abs(k % length)
  for (let i = 0; i < step; i++) {
    const n = arr.pop()
    if (n != null) {
      arr.unshift(n)
    }
  }
  return arr
}

export function rorate2(arr: number[], k: number): number[] {
  const length = arr.length
  if (!k || length === 0) return arr
  const step = Math.abs(k % length)
  const sArr = arr.slice(-step)
  const nArr = arr.slice(0, arr.length - step)
  let newArr = sArr.concat(nArr)
  return newArr
}
// 测试
// const arr = [1, 2,3,4,5,6,7]
// const r =  rorate2(arr, 3)
// console.log(r)
let arr1 = []
for( let i = 0; i < 10 * 10000; i++) {
  arr1.push(i)
}
console.time('rorate1')
rorate1(arr1, 9*10000)
console.timeEnd('rorate1')
let arr2 = []
for( let i = 0; i < 10 * 10000; i++) {
  arr2.push(i)
}
console.time('rorate2')
rorate2(arr2, 9*10000)
console.timeEnd('rorate2')